// --------------------------------------------------------------------------------------------------------------------
// <copyright file="State.cs" company="Microsoft Corporation">
// The MIT License (MIT)
// 
// Copyright (c) 2014, Microsoft Corporation
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace Microsoft.Robotics.Manipulation.ControllerStateMachine
{
    using System.Collections.Generic;

    /// <summary>
    /// Represents a state in a controller state machine.
    /// </summary>
    public class State
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="State"/> class.
        /// </summary>
        /// <param name="controlMode">The control mode of this state.</param>
        /// <param name="operations">Operations to perform in this sate.</param>
        /// <param name="transitionsToEvaluateBeforeDefaults">Transitions to evaluate before default transitions.</param>
        /// <param name="transitionsToEvaluateAfterDefaults">Transitions to evaluate after default transitions.</param>
        /// <param name="applyHaltTransitions">Indicates whether or not to apply halting (e.g. default) transitions.</param>
        public State(
                int controlMode,
                ControllerOperation[] operations,
                Transition[] transitionsToEvaluateBeforeDefaults,
                Transition[] transitionsToEvaluateAfterDefaults,
                bool applyHaltTransitions = true)
        {
            this.ControlMode = controlMode;
            this.Operations = operations;
            this.TransitionsToEvaluateBeforeDefaults = transitionsToEvaluateBeforeDefaults;
            this.TransitionsToEvaluateAfterDefaults = transitionsToEvaluateAfterDefaults;
            this.ApplyHaltTransitions = applyHaltTransitions;

            List<ControllerOperation> list = new List<ControllerOperation>(operations);

            // valid IDs assigned during building process
            this.Id = -1;
        }

        /// <summary>
        /// Gets or sets the control mode.
        /// </summary>
        public int ControlMode { get; set; }

        /// <summary>
        /// Gets or sets state ID.
        /// </summary>
        public int Id { get; set; }

        /// <summary>
        /// Gets or sets operations performed in this state.
        /// </summary>
        public ControllerOperation[] Operations { get; set; }

        /// <summary>
        /// Gets or sets transitions to evaluate before default transitions.
        /// </summary>
        public Transition[] TransitionsToEvaluateBeforeDefaults { get; set; }

        /// <summary>
        /// Gets or sets transitions to evaluate after default transitions.
        /// </summary>
        public Transition[] TransitionsToEvaluateAfterDefaults { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether or not to apply halting (e.g. default) transitions in this state.
        /// </summary>
        public bool ApplyHaltTransitions { get; set; }
    }
}
